#!/usr/bin/env python
# -*- coding: utf-8 -*-
# 时间     : 2021-06-30 23:17
# 作者     : DL (584054432@qq.com)
# 网址     : https://gitee.com/dingliangPython/
# 软件版本 : Python3.7.3
# 功能     ：

import logging
import os
import sqlite3
from ctypes import windll

import win32con

import mysql_client
from sqlite_error import error_code


class Connect(mysql_client.Connect):
    """docstring for Connect"""

    def __init__(self, config):
        super(Connect, self).__init__(config)
        self.log = logging.getLogger('main.oracle_client')
        self.config = config
        # 连接池对象
        self.__pool = None
        self.error_code = error_code

    # 获取odbc连接
    def __get_odbc_connect(self):
        return self.__get_connect()

    # 获取连接池连接
    def __get_pool_connect(self):
        return self.__get_connect()

    # 获取数据库连接
    def __get_connect(self):
        try:
            file_path = self.get_file_path()
            if not os.path.exists(file_path):
                info = "库文件：{}，不存在不能连接数据库".encode('gbk')
                windll.user32.MessageBoxA(0, info, "警告".encode('gbk'), 1 | win32con.MB_ICONWARNING)
                return
            connect = sqlite3.connect(file_path, check_same_thread = False)
            return connect
        except Exception as e:
            self.get_error_info(e)


if __name__ == '__main__':
    import time

    config = {
            'username': 'ygct',
            # 'mode': '短连接',
            'mode': 'ODBC',
            'type': 'mysql',
            'name': 'ics',
            'host': '127.0.0.1',
            'dsn': 'MYSQL',
            'port': 3306,
            'password': 'ygct',
            'database': 'ygct',
            'databasepath': r'D:\CODE\PYTHON\DA_V4\app\config.db',
            # 'charset': 'gbk'
            }
    client = Connect(config)
    sql = "SELECT * FROM appconfig "
    while 1:
        a = client.loadSql(sql, True)
        print(a)
        time.sleep(3)